package ilender.util;

import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.*;

/**
 * Tools for using MyBatis.
 */
public class MyBatisTools{
	/*Instantiation Guard*/private MyBatisTools(){}

	private static SqlSessionFactory sessionFactory=null;

	/**Create and return a MyBatis session.*/
	public static SqlSession openSession() throws Exception{
		if(null==sessionFactory){
			InputStream stream=MyBatisTools.class.getClassLoader().getResourceAsStream("sqlmap-config.xml");
			sessionFactory=new SqlSessionFactoryBuilder().build(stream,PropertiesTools.fetchDatabaseProperties());
		}
		return sessionFactory.openSession();
	}
}
